<?php


namespace App\Controller\Admin;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Admin\TaskAuditIndexRequest;
use App\Request\Admin\TaskIndexRequest;
use App\Request\Admin\TaskNotAllowRequest;
use App\Service\Admin\TaskService;
use Hyperf\Di\Annotation\Inject;

class TaskController extends AbstractController
{

    /**
     * @Inject()
     * @var TaskService
     */
    protected $taskService;

    /**
     * @OperationLog(event="获取任务审核列表",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function auditIndex(TaskAuditIndexRequest $request)
    {
        $where = $request->validated();
        $index = $this->taskService->auditIndex($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="任务审核通过",platform="admin")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Throwable
     */
    public function allow(int $taskId)
    {
        $this->taskService->allow($taskId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="任务审核不通过",platform="admin")
     * @param int $taskId
     * @param TaskNotAllowRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function notAllow(int $taskId, TaskNotAllowRequest $request)
    {
        $validated = $request->validated();
        $this->taskService->notAllow($taskId, $validated['message']);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="获取任务列表",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index(TaskIndexRequest $request)
    {
        $where = $request->validated();
        $index = $this->taskService->index($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="冻结任务",platform="admin")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function block(int $taskId)
    {
        $this->taskService->block($taskId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="解冻任务",platform="admin")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function unblock(int $taskId)
    {
        $this->taskService->unblock($taskId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="任务详情",platform="admin")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function info(int $taskId){
        $task = $this->taskService->info($taskId);
        return $this->response->success($task);
    }
}